import request from '@/utils/request'

// 分页查询文章列表
export function listArticle(params) {
  return request({
    url: '/textRead/textRead/list',
    method: 'get',
    params: params
  })
}

// 根据条件查询文章列表
export function getList(params) {
  return request({
    url: '/textRead/textRead/getList',
    method: 'post',
    data: params
  })
}

// 分页查询文章列表
export function getListPage(pageNum, pageSize) {
  return request({
    url: '/textRead/textRead/getListPage',
    method: 'get',
    params: {
      pageNum: pageNum,
      pageSize: pageSize
    }
  })
}

// 查询文章详情
export function getArticle(id) {
  return request({
    url: '/textRead/textRead/' + id,
    method: 'get'
  })
}

// 新增文章
export function addArticle(data) {
  return request({
    url: '/textRead/textRead/add',
    method: 'post',
    data: data
  })
}

// 修改文章
export function updateArticle(data) {
  return request({
    url: '/textRead/textRead/update',
    method: 'put',
    data: data
  })
}

// 删除文章
export function delArticle(id) {
  return request({
    url: '/textRead/textRead/delete/' + id,
    method: 'delete'
  })
}

// 上传封面图片
export function uploadFile(id, formData) {
  return request({
    url: '/textRead/textRead/filePathImg1/' + id,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

// 文章内容图片上传
export function uploadContentImage(file) {
  const formData = new FormData();
  formData.append('file', file);
  return request({
    url: '/textRead/textRead/contentImage',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}


export function uploadAttachment(id, formData) {
  return request({
    url: '/textRead/textRead/filePathImg1/' + id,
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  });
}

export function uploadAttachs(data) {
  return request({
    url: '/textRead/textRead/getList',
    method: 'post',
    data: data
  })
}

// 逻辑删除文章
export function logicDeleteArticle(id) {
  return request({
    url: "/textRead/textRead/delete/" + id,
    method: "delete"
  })
}

// 隐藏文章
export function hideArticle(id) {
  return request({
    url: "/textRead/textRead/update",
    method: "put",
    data: { id: id, status: 0 }
  })
}

// 显示文章
export function showArticle(id) {
  return request({
    url: "/textRead/textRead/update",
    method: "put",
    data: { id: id, status: 1 }
  })
}

// 批量隐藏
export function batchHideArticle(ids) {
  return request({
    url: "/textRead/textRead/batchHide",
    method: "put",
    data: { ids: ids, status: 0 }
  })
}

// 批量显示
export function batchShowArticle(ids) {
  return request({
    url: "/textRead/textRead/batchShow",
    method: "put",
    data: { ids: ids, status: 1 }
  })
}

// 按条件批量隐藏文章
export function batchHideArticleByCondition(params) {
  return request({
    url: "/textRead/textRead/batchHideByCondition",
    method: "put",
    data: params
  })
}

// 按条件批量显示文章
export function batchShowArticleByCondition(params) {
  return request({
    url: "/textRead/textRead/batchShowByCondition",
    method: "put",
    data: params
  })
}

// 保存草稿
export function saveDraft(data) {
  return request({
    url: '/textRead/textRead/add',
    method: 'post',
    data: { ...data, status: 0 }
  })
}

// 更新草稿
export function updateDraft(data) {
  return request({
    url: '/textRead/textRead/update',
    method: 'put',
    data: { ...data, status: 0 }
  })
}

// 发布草稿
export function publishDraft(id) {
  return request({
    url: '/textRead/textRead/update',
    method: 'put',
    data: { id: id, status: 1 }
  })
}

// 查询草稿列表
export function listDraft(params) {
  return request({
    url: '/textRead/textRead/getList',
    method: 'post',
    data: { ...params, status: 0 }
  })
}
